const baseUrl="/";
let needLoadSportList=false;
function get(url,params,success){
	return ajax(url,params,"GET",success);
	$.get(baseUrl+url,params,function(data){
		if(data.code===-1){
			localStorage.clear();
		}
		success(data);
	},function(data){
		if(error!=undefined){
			error(data);
		}
	});
}
function post(url,params,success){
	return ajax(url,params,"POST",success);
}
function ajax(url,params,type,success,error){
	$.ajax({
		url:baseUrl+url,
		data:params,
		type:type,
		dataType:"json",
		traditional:true,
		headers : { 'Accept' : 'application/json','Content-Type' : 'application/json;charset=utf-8'}, //接口json格式
		success:function(data){
			if(data.code===-1){
				localStorage.clear();
			}
			success(data);
		},
		error:function(data){
			if(error!=undefined){
				error(data);
			}
		},
	});
}

/**
 * [fileLengthFormat 格式化文件大小]
 * @param  {[int]} total [文件大小]
 * @param  {[int]} n     [total参数的原始单位如果为Byte，则n设为1，如果为kb，则n设为2，如果为mb，则n设为3，以此类推]
 * @return {[string]}       [带单位的文件大小的字符串]
 */
function fileLengthFormat(total, n) {
    var format;
    var len = total / (1024.0);
    if (len > 1000) {
        return arguments.callee(len, ++n);
    } else {
        switch (n) {
            case 1:
                format = len.toFixed(2);
                break;
            case 2:
                format = len.toFixed(2);
                break;
            case 3:
                format = len.toFixed(2);
                break;
            case 4:
                format = len.toFixed(2);
                break;
        }
        return format;
    }
}

function formatTime(time) {
	if (typeof time !== 'number' || time < 0) {
		return time
	}

	var hour = parseInt(time / 3600)
	time = time % 3600
	var minute = parseInt(time / 60)
	time = time % 60
	var second = time

	return ([hour, minute, second]).map(function (n) {
		n = n.toString()
		return n[1] ? n : '0' + n
	}).join(':')
}

function dateFormat(fmt, date) {
    let ret;
    let opt = {
        "Y+": date.getFullYear().toString(),        // 年
        "m+": (date.getMonth() + 1).toString(),     // 月
        "d+": date.getDate().toString(),            // 日
        "H+": date.getHours().toString(),           // 时
        "M+": date.getMinutes().toString(),         // 分
        "S+": date.getSeconds().toString()          // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
}

function formatLocation(longitude, latitude) {
	if (typeof longitude === 'string' && typeof latitude === 'string') {
		longitude = parseFloat(longitude)
		latitude = parseFloat(latitude)
	}

	longitude = longitude.toFixed(2)
	latitude = latitude.toFixed(2)

	return {
		longitude: longitude.toString().split('.'),
		latitude: latitude.toString().split('.')
	}
}
var dateUtils = {
	UNITS: {
		'年': 31557600000,
		'月': 2629800000,
		'天': 86400000,
		'小时': 3600000,
		'分钟': 60000,
		'秒': 1000
	},
	humanize: function (milliseconds) {
		var humanize = '';
		for (var key in this.UNITS) {
			if (milliseconds >= this.UNITS[key]) {
				humanize = Math.floor(milliseconds / this.UNITS[key]) + key + '前';
				break;
			}
		}
		return humanize || '刚刚';
	},
	format: function (dateStr) {
		var date = this.parse(dateStr)
		var diff = Date.now() - date.getTime();
		if (diff < this.UNITS['天']) {
			return this.humanize(diff);
		}
		var _format = function (number) {
			return (number < 10 ? ('0' + number) : number);
		};
		return date.getFullYear() + '/' + _format(date.getMonth() + 1) + '/' + _format(date.getDay()) + '-' +
			_format(date.getHours()) + ':' + _format(date.getMinutes());
	},
	parse: function (str) { //将"yyyy-mm-dd HH:MM:ss"格式的字符串，转化为一个Date对象
		var a = str.split(/[^0-9]/);
		return new Date(a[0], a[1] - 1, a[2], a[3], a[4], a[5]);
	}
};

function getCurrentMonthFirst() {
	var date = new Date()
	date.setDate(1)
	return date
}

function getCurrentMonthLast() {
	var date = new Date();
	var currentMonth = date.getMonth();
	var nextMonth = ++currentMonth;
	var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
	var oneDay = 1000 * 60 * 60 * 24;
	return new Date(nextMonthFirstDay - oneDay);
}

function format(fmt, date) {
	var o = {
		"M+": date.getMonth() + 1, //月份
		"d+": date.getDate(), //日
		"h+": date.getHours(), //小时
		"m+": date.getMinutes(), //分
		"s+": date.getSeconds(), //秒
		"q+": Math.floor((date.getMonth() + 3) / 3), //季度
		"S": date.getMilliseconds() //毫秒
	};
	if (/(y+)/.test(fmt))
		fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt))
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}

function tt() {
	 var d = new Date();
       var year = d.getFullYear();
       var month = d.getMonth() + 1;
       var date = d.getDate();
       var day = d.getDay();
       var curDateTime = year;
       if (month > 9)
          curDateTime = curDateTime + "" + month;
       else
          curDateTime = curDateTime + "0" + month;
       if (date > 9)
          curDateTime = curDateTime + ""  + date;
       else
          curDateTime = curDateTime + "0" + date;
       return curDateTime;
}

function formatYMdHms(d) {
	var year = d.getFullYear();
	var month = d.getMonth() + 1;
	var date = d.getDate();
	var day = d.getDay();
	var curDateTime = year+"-";
	if (month > 9){
		curDateTime = curDateTime + "" + month;
	}else{
		curDateTime = curDateTime + "0" + month;
	}
	curDateTime+="-";
	if (date > 9){
		curDateTime = curDateTime + ""  + date;
	}else{
		curDateTime = curDateTime + "0" + date;
	}
	return curDateTime;
}

function alert(msg)
{
	layer.msg(msg);
};

function consoleLog(msg){
	console.log(msg);
}

//DES加密
function encryptByDES(message, key){
	var keyHex = CryptoJS.enc.Utf8.parse(key);
	var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7
	});
	return encrypted.ciphertext.toString();
}
//DES解密
function decryptByDES(ciphertext, key){
	var keyHex = CryptoJS.enc.Utf8.parse(key);
	var decrypted = CryptoJS.DES.decrypt({
		ciphertext: CryptoJS.enc.Hex.parse(ciphertext)
	}, keyHex, {
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7
	});
	var result_value = decrypted.toString(CryptoJS.enc.Utf8);
	return result_value;
}
//加密
function encryptLocalStorage(jsonData,key)
{
	if(key==undefined  || key==null){key='12qwaszx';}
	let data=JSON.stringify(jsonData);
	let wordArray = CryptoJS.enc.Utf8.parse(data);
	let base64 = CryptoJS.enc.Base64.stringify(wordArray);
	let result=encryptByDES(base64,key);
	return result;
}
//解密
function decryptLocalStorage(data,key)
{
	if(key==undefined || key==null){key='12qwaszx';}
	let _data=decryptByDES(data,key);
	let parsedWordArray = CryptoJS.enc.Base64.parse(_data);
	let result= parsedWordArray.toString(CryptoJS.enc.Utf8);
	return JSON.parse(result);
}

function checkLogin(layer)
{
	let u=localStorage.getItem("a@m");
	let loginU={};
	if(u==undefined){
		layer.msg('请登录', {icon: 1, time: 500},function () {
			window.location = 'logout';
		});
		return;
	}else{
		loginU=decryptLocalStorage(u);
	}
	request.token({token:loginU.token},function(data) {
		if(data.data==0){
			layer.msg('请登录', {icon: 1, time: 500},function () {
				window.location = 'logout';
			});
			return;
		}else{
			localStorage.setItem("a@m", encryptLocalStorage(loginU));
		}
	});
}

function getNowFormatDate() {
	let date = new Date();
	let sep= "-";
	let month = date.getMonth() + 1;
	let strDate = date.getDate();
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	let currentDate = date.getFullYear() + sep + month + sep + strDate;
	return currentDate;
}

function setTableHeight()
{
	setTimeout(function(){
		let windowHeight=$(window).height();
		let tableFieldset=$(".table-search-fieldset").height();
		if(tableFieldset=='' || tableFieldset==undefined)
		{
			tableFieldset=0;
		}
		$(".layui-table-body").height(windowHeight-tableFieldset-190);

		$(window).resize(function() {
			let windowHeight=$(window).height();
			let tableFieldset=$(".table-search-fieldset").height();
			if(tableFieldset=='' || tableFieldset==undefined)
			{
				tableFieldset=0;
			}
			$(".layui-table-body").height(windowHeight-tableFieldset-190);
		});
	},300);
}

//省级
function provinceList(form,token,provinceId,cityId,districtId,schoolId)
{
	request.provinceList({token:token},function(result){
		if(result.code==0){
			let data=result.data;
			let option="<option value=''>请选择省</option>";
			if(data.length>0)
			{
				for (let i = 0; i < data.length; i++) {
					if(data[i].areaId==provinceId)
					{
						option+="<option value='"+data[i].areaId+"' selected>"+data[i].areaName+"</option>";
					}else{
						option+="<option value='"+data[i].areaId+"'>"+data[i].areaName+"</option>";
					}

				}
			}
			$("#province").html(option);
			form.render("select");

			if(cityId!=undefined && cityId!=''){
				cityList(form,token,provinceId,cityId,districtId,schoolId);
			}
		}
	});
}

//市级
function cityList(form,token,provinceId,cityId,districtId,schoolId)
{
	request.cityList({token:token,parentId:provinceId},function(result){
		if(result.code==0){
			let data=result.data;
			let option="<option value=''>请选择市</option>";
			if(data.length>0)
			{
				for (let i = 0; i < data.length; i++) {
					if(data[i].areaId==cityId) {
						option += "<option value='" + data[i].areaId + "' selected>" + data[i].areaName + "</option>";
					}else{
						option += "<option value='" + data[i].areaId + "'>" + data[i].areaName + "</option>";
					}
				}
			}
			$("#city").html(option);
			form.render("select");
			if(districtId!=undefined && districtId!=''){
				districtList(form,token,provinceId,cityId,districtId,schoolId)
			}
		}
	});
}

//区级
function districtList(form,token,provinceId,cityId,districtId,schoolId)
{
	request.districtList({token:token,parentId:cityId},function(result){
		if(result.code==0){
			let data=result.data;
			let option="<option value=''>请选择区</option>";
			if(data.length>0)
			{
				for (let i = 0; i < data.length; i++) {
					if(data[i].areaId==districtId) {
						option += "<option value='" + data[i].areaId + "' selected>" + data[i].areaName + "</option>";
					}else{
						option += "<option value='" + data[i].areaId + "'>" + data[i].areaName + "</option>";
					}
				}
			}
			$("#district").html(option);
			form.render("select");
			if(schoolId!=undefined && schoolId!='') {
				schoolList(form, token, provinceId, cityId, districtId, schoolId);
			}
		}
	});
}
//学校
function schoolList(form,token,provinceId,cityId,districtId,schoolId)
{
	request.schoolList({token:token,keyWord:JSON.stringify({provinceId:provinceId,cityId:cityId,districtId:districtId})},function(result){
		if(result.code==0){
			let data=result.data;
			let option="<option value=''>请选择学校</option>";
			if(data.length>0)
			{
				for (let i = 0; i < data.length; i++) {
					if(data[i].schoolId==schoolId){
						option+="<option value='"+data[i].schoolId+"' selected>"+data[i].schoolName+"</option>";
					}else{
						option+="<option value='"+data[i].schoolId+"'>"+data[i].schoolName+"</option>";
					}
				}
			}
			$("#school").html(option);
			form.render("select");
		}
	});
}

//体测项目
function sportList(form,token,gradeCode,gender,sportCode)
{
	request.sportList({token:token,gradeCode:gradeCode,gender:gender},function(result){
		if(result.code==0){
			let data=result.data;
			let option="<option value=''>请选择体测项目</option>";
			if(data.length>0)
			{
				for (let i = 0; i < data.length; i++) {
					if(data[i].sportCode!='bmi')
					{
						option+="<option value='tall'>身高</option>";
						option+="<option value='weight'>体重</option>";
						if(data[i].sportCode==sportCode){
							option+="<option value='"+data[i].sportCode+"' selected>"+data[i].sportName+"</option>";
						}else{
							option+="<option value='"+data[i].sportCode+"'>"+data[i].sportName+"</option>";
						}
					}

				}
			}
			$("#sportCode").html(option);
			form.render("select");
		}
	});
}


/**
 * 选择体测任务
 * @param tableSelect
 * @param token
 * @param storageFlag
 */
function tableSelectTask(tableSelect,token,storageFlag,schoolId){
	let tableUrl="/admin/v1/fitness-test-task/page?schoolId="+schoolId+"&token="+token;
	tableSelect.render({
		elem: '#taskName',
		checkedKey: 'id',
		searchFlag:true,
		searchKey: 'taskName',
		table: {
			url: tableUrl,
			cols: [[
				{ type: 'radio'},
				// {field: 'taskId',width:80, title: 'ID'},
				{field: 'schoolName', align:"center", title: '学校', sort: true},
				{field: 'taskName', title: '体测任务',width:220}
			]]
		},
		done: function (elem, data) {
			if(data.data.length>0)
			{
				if(storageFlag!=undefined && storageFlag){
					let keyWordTaskId=data.data[0].taskId;
					let keyWordTaskName=data.data[0].taskName;
					if(keyWordTaskId!=undefined && keyWordTaskId!='undefined'){localStorage.setItem("keyWordTaskId",keyWordTaskId);}
					if(keyWordTaskName!=undefined && keyWordTaskName!='undefined'){localStorage.setItem("keyWordTaskName", keyWordTaskName);}
				}
				taskId=data.data[0].taskId;
				taskName=data.data[0].taskName;

				$("#taskId").val(data.data[0].taskId);
				$("#taskName").val(data.data[0].taskName);

				tableSelectClassByTask(tableSelect,token,schoolId,taskId,false);

			}else{
				if(storageFlag!=undefined && storageFlag){
					let keyWordTaskId = "";
					let keyWordTaskName = "";
					if (keyWordTaskId != undefined && keyWordTaskId != 'undefined') {
						localStorage.setItem("keyWordTaskId", keyWordTaskId);
					}
					if (keyWordTaskName != undefined && keyWordTaskName != 'undefined') {
						localStorage.setItem("keyWordTaskName", keyWordTaskName);
					}
				}
				taskId="";
				taskName="";
				$("#taskId").val("");
				$("#taskName").val("");
			}

		},
		clear: function () {
			if(storageFlag!=undefined && storageFlag){
				let keyWordTaskId = "";
				let keyWordTaskName = "";
				if (keyWordTaskId != undefined && keyWordTaskId != 'undefined') {
					localStorage.setItem("keyWordTaskId", keyWordTaskId);
				}
				if (keyWordTaskName != undefined && keyWordTaskName != 'undefined') {
					localStorage.setItem("keyWordTaskName", keyWordTaskName);
				}
			}
			taskId="";
			taskName="";
			$("#taskId").val("");
			$("#taskName").val("");

		}
	})
}

/**
 * 选择学校
 * @param tableSelect
 * @param token
 * @param storageFlag
 */
function tableSelectSchool(tableSelect,token,storageFlag,loadClassFlag,loadTaskFlag){
	let tableUrl="/admin/v1/school/page?token="+token;
	tableSelect.render({
		elem: '#schoolName',
		checkedKey: 'id',
		searchFlag:true,
		searchKey: 'schoolName',
		table: {
			url: tableUrl,
			cols: [[
				{ type: 'radio'},
				// {field: 'schoolId',width:80, title: 'ID'},
				{field: 'provinceName', align:"center", title: '省/直辖市', sort: true},
				{field: 'cityName', align:"center", title: '市', sort: true},
				{field: 'districtName', align:"center", title: '区/县', sort: true},
				{field: 'schoolName', title: '学校',width:220}
			]]
		},
		done: function (elem, data) {
			if(data.data.length>0)
			{
				if(storageFlag!=undefined && storageFlag){
					let keyWordSchoolId=data.data[0].schoolId;
					let keyWordSchoolName=data.data[0].schoolName;
					if(keyWordSchoolId!=undefined && keyWordSchoolId!='undefined'){localStorage.setItem("keyWordSchoolId",keyWordSchoolId);}
					if(keyWordSchoolName!=undefined && keyWordSchoolName!='undefined'){localStorage.setItem("keyWordSchoolName", keyWordSchoolName);}
				}
				schoolId=data.data[0].schoolId;
				schoolName=data.data[0].schoolName;
				schoolType=data.data[0].schoolType;

				selectOptionGradeCode(form,schoolType);

				if(loadClassFlag!=undefined && loadClassFlag)
				{
					tableSelectClassByTask(tableSelect,token,schoolId,taskId,false);
				}

				if(loadTaskFlag!=undefined && loadTaskFlag)
				{
					tableSelectTask(tableSelect,token,true,schoolId);
				}

				$("#schoolId").val(data.data[0].schoolId);
				$("#schoolName").val(data.data[0].schoolName);
			}else{
				if(storageFlag!=undefined && storageFlag){
					let keyWordSchoolId = "";
					let keyWordSchoolName = "";
					if (keyWordSchoolId != undefined && keyWordSchoolId != 'undefined') {
						localStorage.setItem("keyWordSchoolId", keyWordSchoolId);
					}
					if (keyWordSchoolName != undefined && keyWordSchoolName != 'undefined') {
						localStorage.setItem("keyWordSchoolName", keyWordSchoolName);
					}
				}
				schoolId="";
				schoolName="";
				$("#schoolId").val("");
				$("#schoolName").val("");
			}

		},
		clear: function () {
			if(storageFlag!=undefined && storageFlag){
				let keyWordSchoolId = "";
				let keyWordSchoolName = "";
				if (keyWordSchoolId != undefined && keyWordSchoolId != 'undefined') {
					localStorage.setItem("keyWordSchoolId", keyWordSchoolId);
				}
				if (keyWordSchoolName != undefined && keyWordSchoolName != 'undefined') {
					localStorage.setItem("keyWordSchoolName", keyWordSchoolName);
				}
			}
			schoolId="";
			schoolName="";
			$("#schoolId").val("");
			$("#schoolName").val("");

		}
	})
}

function selectOptionGradeCode(form,schoolType)
{
	if(schoolType!=undefined && form!=undefined)
	{
		let option="<option value=''>请选择年级</option>";
		// if(schoolType=='primary')
		// {
			option+='<option value="11">一年级</option>';
			option+='<option value="12">二年级</option>';
			option+='<option value="13">三年级</option>';
			option+='<option value="14">四年级</option>';
			option+='<option value="15">五年级</option>';
			option+='<option value="16">六年级</option>';
		// }
		// if(schoolType=='middle')
		// {
			option+='<option value="21">七年级</option>';
			option+='<option value="22">八年级</option>';
			option+='<option value="23">九年级</option>';
		// }
		// if(schoolType=='high')
		// {
			option+='<option value="31">高一</option>';
			option+='<option value="32">高二</option>';
			option+='<option value="33">高三</option>';
		// }
		$("#gradeCode").html(option);
		form.render("select");
	}
}

function selectOptionGradeCodeByTask(form,data)
{
	if(data!=undefined && form!=undefined)
	{
		let option="<option value=''>请选择年级</option>";
		if(data.length>0){
			for(let i=0;i<data.length;i++)
			{
				option+='<option value="'+data[i].gradeCode+'">'+data[i].gradeName+'</option>';
			}
		}
		$("#gradeCode").html(option);
		form.render("select");
	}
}
/**
 * 选择班级
 * @param tableSelect
 * @param token
 * @param storageFlag
 */
function tableSelectClass(tableSelect,token,schoolId,loadStudentFlag){
	let tableUrl="/admin/v1/class/page?schoolId="+schoolId+"&token="+token;
	tableSelect.render({
		elem: '#className',
		checkedKey: 'id',
		searchFlag:true,
		searchKey: 'className',
		table: {
			url: tableUrl,
			cols: [[
				{ type: 'radio'},
				// {field: 'classId',width:80, title: 'ID'},
				// {field: 'schoolName', align:"center", title: '学校', sort: true},
				{field: 'gradeName', align:"center", title: '年级', sort: true},
				// {field: 'classYear', align:"center", title: '年份', sort: true},
				{field: 'className', align:"center", title: '班级', sort: true}
			]]
		},
		done: function (elem, data) {
			if(data.data.length>0)
			{
				classId=data.data[0].classId;
				gradeCode=data.data[0].gradeCode;
				className=data.data[0].className;

				if(loadStudentFlag!=undefined && loadStudentFlag)
				{
					tableSelectStudent(tableSelect,token,classId);
				}
				$("#classId").val(data.data[0].classId);
				$("#gradeCode").val(data.data[0].gradeCode);
				let gradeName="";
				if(gradeCode=='11'){gradeName="一年级";}
				if(gradeCode=='12'){gradeName="二年级";}
				if(gradeCode=='13'){gradeName="三年级";}
				if(gradeCode=='14'){gradeName="四年级";}
				if(gradeCode=='15'){gradeName="五年级";}
				if(gradeCode=='16'){gradeName="六年级";}

				if(gradeCode=='21'){gradeName="七年级";}
				if(gradeCode=='22'){gradeName="八年级";}
				if(gradeCode=='23'){gradeName="九年级";}

				if(gradeCode=='31'){gradeName="高一";}
				if(gradeCode=='32'){gradeName="高二";}
				if(gradeCode=='33'){gradeName="高三";}

				if(gradeCode=='41'){gradeName="大一";}
				if(gradeCode=='42'){gradeName="大二";}
				if(gradeCode=='43'){gradeName="大三";}
				if(gradeCode=='44'){gradeName="大四";}
				if(form!=undefined)
				{
					form.render("select");
				}
				$("#gradeName").val(gradeName);
				$("#className").val(data.data[0].className);
			}else{
				classId="";
				gradeCode="";
				gradeName="";
				className="";
				$("#classId").val("");
				$("#gradeCode").val("");
				$("#gradeName").val("");
				$("#className").val("");
			}

		},
		clear: function () {
			classId="";
			gradeCode="";
			gradeName="";
			className="";
			$("#classId").val("");
			$("#gradeCode").val("");
			$("#gradeName").val("");
			$("#className").val("");
		}
	})
}

/**
 * 根据任务获取班级
 * @param tableSelect
 * @param token
 * @param storageFlag
 */
function tableSelectClassByTask(tableSelect,token,schoolId,taskId,loadStudentFlag){
	let params={token:token,schoolId:schoolId,taskId:taskId};
	request.otherGetMethod('class','classListByTask',params,function(result){
		if(result.code==0){
			let gradeData=result.data.gradeList;
			selectOptionGradeCodeByTask(form,gradeData);
			let data=result.data.classList;
			let colsData=[[
				{ type: "radio"},
				{field: "gradeName", align:"center", title: "年级"},
				{field: "className", align:"center", title: "班级"}
			]];

			tableSelect.render({
				elem: '#className',
				checkedKey: 'id',
				searchFlag:true,
				searchKey: 'className',
				table: {
					data: data,
					cols: colsData
				},
				done: function (elem, data) {
					if(data.data.length>0)
					{
						classId=data.data[0].classId;
						gradeCode=data.data[0].gradeCode;
						className=data.data[0].className;
						if(loadStudentFlag!=undefined && loadStudentFlag)
						{
							tableSelectStudent(tableSelect,token,classId);
						}
						$("#classId").val(data.data[0].classId);
						$("#gradeCode").val(data.data[0].gradeCode);
						let gradeName="";
						if(gradeCode=='11'){gradeName="一年级";}
						if(gradeCode=='12'){gradeName="二年级";}
						if(gradeCode=='13'){gradeName="三年级";}
						if(gradeCode=='14'){gradeName="四年级";}
						if(gradeCode=='15'){gradeName="五年级";}
						if(gradeCode=='16'){gradeName="六年级";}

						if(gradeCode=='21'){gradeName="七年级";}
						if(gradeCode=='22'){gradeName="八年级";}
						if(gradeCode=='23'){gradeName="九年级";}

						if(gradeCode=='31'){gradeName="高一";}
						if(gradeCode=='32'){gradeName="高二";}
						if(gradeCode=='33'){gradeName="高三";}

						if(gradeCode=='41'){gradeName="大一";}
						if(gradeCode=='42'){gradeName="大二";}
						if(gradeCode=='43'){gradeName="大三";}
						if(gradeCode=='44'){gradeName="大四";}
						if(form!=undefined)
						{
							form.render("select");
						}
						$("#gradeName").val(gradeName);
						$("#className").val(data.data[0].className);
					}else{
						classId="";
						gradeCode="";
						gradeName="";
						className="";
						$("#classId").val("");
						$("#gradeCode").val("");
						$("#gradeName").val("");
						$("#className").val("");
					}

				},
				clear: function () {
					classId="";
					gradeCode="";
					gradeName="";
					className="";
					$("#classId").val("");
					$("#gradeCode").val("");
					$("#gradeName").val("");
					$("#className").val("");
				}
			})
		}
	});

}



/**
 * 选择学生
 * @param tableSelect
 * @param token
 * @param storageFlag
 */
function tableSelectStudent(tableSelect,token,classId){
	let tableUrl="/admin/v1/student/page?classId="+classId+"&token="+token;
	tableSelect.render({
		elem: '#studentName',
		checkedKey: 'id',
		searchFlag:true,
		searchKey: 'studentName',
		table: {
			url: tableUrl,
			cols: [[
				{ type: 'radio'},
				// {field: 'classId',width:80, title: 'ID'},
				{field: 'gradeName', align:"center", title: '年级', sort: true},
				{field: 'className', align:"center", title: '班级', sort: true},
				{field: 'studentName', align:"center", title: '学生', sort: true},
				{field: 'studentNo', align:"center", title: '学籍号', sort: true},
				{field: 'gender', align:"center", title: '性别', sort: true}
			]]
		},
		done: function (elem, data) {
			if(data.data.length>0)
			{
				studentId=data.data[0].studentId;
				studentName=data.data[0].studentName;
				gender=data.data[0].gender;
				studentNo=data.data[0].studentNo;
				$("#studentId").val(data.data[0].studentId);
				$("#studentName").val(data.data[0].studentName);
				$("#gender").val(data.data[0].gender);
				$("#studentNo").val(data.data[0].studentNo);
			}else{
				studentId="";
				studentName="";
				gender="";
				studentNo="";
				$("#studentId").val("");
				$("#studentName").val("");
				$("#gender").val("");
				$("#studentNo").val("");
			}

		},
		clear: function () {
			studentId="";
			studentName="";
			gender="";
			studentNo="";
			$("#studentId").val("");
			$("#studentName").val("");
			$("#gender").val("");
			$("#studentNo").val("");

		}
	})
}



function searchFieldset()
{
	let show=$('.search-display-btn').attr("show");
	let searchFieldsetStatus=localStorage.getItem("searchFieldsetStatus");
	if(searchFieldsetStatus!=undefined && searchFieldsetStatus!=''){
		show=searchFieldsetStatus;
	}
	if(show=='0')
	{
		localStorage.setItem("searchFieldsetStatus","1");
		$('.search-display-btn').attr("show","1");
		$('.search-display-btn').html('<i class="fa fa-angle-up"></i>折叠');
		$($('.layui-form')[0]).show();
	}else{
		localStorage.setItem("searchFieldsetStatus","0");
		$('.search-display-btn').attr("show","0");
		$('.search-display-btn').html('<i class="fa fa-angle-down"></i>展开');
		$($('.layui-form')[0]).hide();
	}
	// setTableHeight();
}



